/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;

import Clases.Consulta;
import Clases.Producto;
import Clases.Solicitud;
import Clases.SolicitudDetalle;
import java.util.List;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Ricardo
 */
public class VerSolicitudes extends javax.swing.JFrame {

    /**
     * Creates new form VerSolicitudes
     */
    public VerSolicitudes() {
        initComponents();
        if (Consulta.getSolicitud().size() > 0) {
            DefaultTableModel modelo = (DefaultTableModel) tablaSolicitudes.getModel();
            String[] solicitud = new String[5];
            for (Solicitud s : Consulta.getSolicitud()) {
                List<SolicitudDetalle> sd = s.getDetalles();
                for (SolicitudDetalle ss : sd) {
                    Producto p = ss.getProducto();
                    solicitud[0] = p.getCodigoProducto();
                    solicitud[1] = p.getDescripcionProducto();
                    solicitud[2] = "" + ss.getCantidad();
                    solicitud[3] = s.getDependencia().getDepartamento();
                    solicitud[4] = s.getCodigoSolicitud();
                }
                modelo.addRow(solicitud);
            }
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        popVerMas = new javax.swing.JPopupMenu();
        verMas = new javax.swing.JMenuItem();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tablaSolicitudes = new javax.swing.JTable();

        verMas.setText("Ver más Información");
        verMas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                verMasActionPerformed(evt);
            }
        });
        popVerMas.add(verMas);

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Solicitudes");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Solicitudes"));

        tablaSolicitudes.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Código del Producto", "Producto", "Cantidad Solicitada", "Dependencia", "Código de Solicitud"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, true, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tablaSolicitudes.setComponentPopupMenu(popVerMas);
        tablaSolicitudes.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        tablaSolicitudes.getTableHeader().setReorderingAllowed(false);
        jScrollPane1.setViewportView(tablaSolicitudes);
        tablaSolicitudes.getColumnModel().getColumn(0).setResizable(false);
        tablaSolicitudes.getColumnModel().getColumn(1).setResizable(false);
        tablaSolicitudes.getColumnModel().getColumn(2).setResizable(false);
        tablaSolicitudes.getColumnModel().getColumn(3).setResizable(false);
        tablaSolicitudes.getColumnModel().getColumn(4).setResizable(false);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 617, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 246, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void verMasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_verMasActionPerformed
        // TODO add your handling code here:
        try{
            int fila = tablaSolicitudes.getSelectedRow();
        if (fila != -1) {
            String codigo = tablaSolicitudes.getValueAt(fila, 4).toString();
            VerSolicitud vs = new VerSolicitud();
            vs.llenarTabla(codigo);
            vs.setVisible(true);
        }
        }catch(Exception e){}

    }//GEN-LAST:event_verMasActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPopupMenu popVerMas;
    private javax.swing.JTable tablaSolicitudes;
    private javax.swing.JMenuItem verMas;
    // End of variables declaration//GEN-END:variables
}
